import 'package:intl/intl.dart';

extension DateTimeExtension on DateTime {
  /// 获取当前时间的毫秒级时间戳（北京时间）
  static String get beijingTimestampInMillis {
    final beijingTime = DateTime.now(); // UTC+8 转为北京时间 //
    return beijingTime.millisecondsSinceEpoch.toString();
  }

  /// 获取格式化的北京时间字符串（可选）
  String formattedBeijingTime([String pattern = 'yyyy-MM-dd HH:mm:ss']) {
    final formatter = DateFormat(pattern);
    final beijingTime = toUtc().add(const Duration(hours: 8));
    return formatter.format(beijingTime);
  }

  String formatWeekDate() {
    final formatter = DateFormat('M月d日');
    const weekdayMap = {
      DateTime.monday: '周一',
      DateTime.tuesday: '周二',
      DateTime.wednesday: '周三',
      DateTime.thursday: '周四',
      DateTime.friday: '周五',
      DateTime.saturday: '周六',
      DateTime.sunday: '周日',
    };
    return '${formatter.format(this)}(${weekdayMap[weekday]})';
  }
}
